package com.tinysand.advert.entity;

import com.tinysand.advert.constant.CommonStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;

/**
 * 广告投放服务用户实体类定义
 *
 * Created By TINY
 * Create Time 2020/2/15
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "ad_user")
@EntityListeners(AuditingEntityListener.class)
public class AdvertUser {

    /* 用户表自增主键 */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

    /* 用户名 */
    @Column(name = "username", nullable = false)
    private String username;

    /* 对应用户的token */
    @Column(name = "token", nullable = false)
    private String token;

    /* 用户状态 */
    @Column(name = "user_status", nullable = false)
    private Integer userStatus;

    /* 用户数据创建时间 */
    @Column(name = "create_time", nullable = false)
    @CreatedDate // 使用JPA审计自动维护创建时间
    private Date createTime;

    /* 用户数据更新时间 */
    @Column(name = "update_time", nullable = false)
    @LastModifiedDate // 使用JPA审计自动维护更新时间
    private Date updateTime;

    public AdvertUser(String username, String token) {
        this.username = username;
        this.token = token;
        this.userStatus = CommonStatus.VALID.getStatus();
    }
}
